package com.example.xiongmao.mapper;

import com.example.xiongmao.anno.AutoFill;
import com.example.xiongmao.entity.Admin;
import com.example.xiongmao.entity.DTO.admin.addAdminDTO;
import com.example.xiongmao.entity.DTO.admin.adminChargeDTO;
import com.example.xiongmao.entity.VO.admin.adminChargeVO;
import com.example.xiongmao.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface adminChargeMapper {

    List<adminChargeVO> list(adminChargeDTO adminchargeDTO);


    @AutoFill(OperationType.INSERT)
    @Insert("INSERT INTO admin (username, password, email,real_name,role, phone_number, img_url,last_login_time, created_time, updated_time, status) " +
            "VALUES (#{username}, '123456', #{email},#{realName},#{role}, #{phoneNumber}, #{imgUrl}, #{lastLoginTime},#{createdTime}, #{updatedTime}, #{status})")
    void add(addAdminDTO addAdmin);

    @Select("select * from admin where id = #{id}")
    adminChargeVO getById(Integer id);

    @AutoFill(OperationType.UPDATE)
    void updateAdmin(addAdminDTO addAdmin);

    void deleteAdminBatch(List<Integer> ids);

    @AutoFill(OperationType.UPDATE)
    @Update("update admin set status=0 where id =#{id}")
    void adminDisable(Long id);

    @AutoFill(OperationType.UPDATE)
    @Update("update admin set status=1 where id =#{id}")
    void adminunDisable(Long id);



    // 查询账号（登录）
    @Select("select * from admin where username=#{username}")
    Admin getByUserName(String username);

    // admin注册账号
    @AutoFill(OperationType.INSERT)
    @Insert("insert into admin (username,password,email,real_name,role,phone_number,created_time, updated_time,status) values (#{username},#{password},#{email},'尊敬的新店长',#{role},#{phoneNumber},#{createdTime}, #{updatedTime},#{status})")
    void addRegister(Admin adminregistDTO);
}
